package engine.ui
{
	import engine.data.ModelLocator;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.ui.lite.BaseUI;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import newx.com.config.StaticIni;
	import newx.com.control.button.NxButton;
	import newx.com.control.text.NxLabel;
	import newx.com.control.window.NxWindowEvent;
	
	public class CDClearTypeUI extends BaseUI
	{
		private static var _self:CDClearTypeUI;
		private static var _model:ModelLocator;
		public var btn_ok:NxButton;
		public var txt_info:NxLabel;
		public var checkbox:MovieClip;
		public var lab_notice:NxLabel;
		public var _isopen:int = 1;
		//private  var _colse	=	2;
		private var typeArr:Array;
		public function CDClearTypeUI(popupUI:Boolean=true)
		{
			super(popupUI);
		}
		
		public static function getInstance():CDClearTypeUI
		{
			if(_self == null)
			{
				_self = new CDClearTypeUI();
			}
			return _self;
		}
		
		override public function Init():void
		{
			typeArr					=	[];
			checkbox.buttonMode 	= 	true;
			lab_notice.buttonMode 	= 	true;
			_model = ModelLocator.getInstance();
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_SEND_CLEAR_CD_CONSUME), onShow);
		}
		
		private function oncheckboxHandle(e:MouseEvent):void
		{
			if (_isopen == 1)
			{
				checkbox.gotoAndStop(2);
				_isopen = 2;
			}else
				if (_isopen == 2)
				{
					checkbox.gotoAndStop(1);
					_isopen = 1;
				}
		}
		private function onShow(e:CustomMsgEvent):void
		{
			var buffArr	:Array	=	e.pList
			addtype(buffArr);
		}
		public function addtype(arr:Array):void
		{
			//typeArr				=	buffArr;
			typeArr				=	arr;
			if (_isopen == 1)
			{
				txt_info.htmlStr = StaticIni.getSwfLangStrVar("UIStr_1001811", [typeArr[2]]);
				show();
			}else
			{
				SystemSender.getInstance().CustomMsgEx(
					(CustomToServerFlag.CLEINT_CUSTOMMSG_REQUEST_CLEAR_CD ),
					[typeArr[0],typeArr[1]]);
			}
		}
		private function onClickClose(e:NxWindowEvent):void
		{
			hide();
		}
		
		private function onGoldHandle(e:MouseEvent):void
		{
		}
		
		private function onActivityHandle(e:MouseEvent):void
		{
			SystemSender.getInstance().CustomMsgEx(
						(CustomToServerFlag.CLEINT_CUSTOMMSG_REQUEST_CLEAR_CD ),
							[typeArr[0],typeArr[1]]);
			
			hide();
		}
		/**
		 *添加监听 
		 * 
		 */
		private function addListenter():void
		{
			checkbox.addEventListener(MouseEvent.CLICK, oncheckboxHandle);
			lab_notice.addEventListener(MouseEvent.CLICK, oncheckboxHandle);
			windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,onClickClose);
			btn_ok.addEventListener(MouseEvent.CLICK,onActivityHandle);
		}
		
		/**
		 *是否需要打开提示框
		 * 1 打开
		 * 2 关闭
		 */
		public function isShowClearUI():int
		{
			return _isopen
		}
		/**
		 *移除监听 
		 * 
		 */
		private function removeListenter():void
		{
			checkbox.removeEventListener(MouseEvent.CLICK, oncheckboxHandle);
			lab_notice.removeEventListener(MouseEvent.CLICK, oncheckboxHandle);
			windowBG.removeEventListener(NxWindowEvent.WINDOW_CLOSE, onClickClose);
			btn_ok.removeEventListener(MouseEvent.CLICK,onActivityHandle);
		}
		
		override protected function BeforeShow():void
		{
			checkbox.gotoAndStop(_isopen);
			addListenter();
		}
		
		override protected function AfterHide():void
		{
			removeListenter();
		}
		
	}
}